<?php

use App\Http\Controllers\Frontend\Apply;
use App\Http\Controllers\Frontend\AuthController;
use App\Http\Controllers\Frontend\Demand;
use App\Http\Controllers\Frontend\EdgeManage;
use App\Http\Controllers\Frontend\Service;
use App\Http\Controllers\Frontend\UserManage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});


#######################################################################
#                 用户登陆认证相关接口
#######################################################################
Route::group(['prefix' => 'user'], function () {
    Route::get('login', [AuthController::class, 'phoneLogin']);
    Route::get('mini-login', [AuthController::class, 'miniLogin']);
    Route::get('register', [UserManage\UserController::class, 'register']);
});


#######################################################################
#                   用户相关接口
#######################################################################
Route::group(['prefix' => 'user', 'middleware' => ['auth:sanctum']], function () {
    Route::get('logout', [AuthController::class, 'logout']);
    Route::post('edit/{id}', [UserManage\UserController::class, 'edit']);
    Route::post('real-auth/{id}', [UserManage\UserController::class, 'realAuth']);

    //收藏相关
    Route::post('favorite', [UserManage\UserController::class, 'favorite']);
    Route::get('favorite-index', [UserManage\UserController::class, 'favoriteIndex']);
});
Route::group(['prefix' => 'user', 'middleware' => ['auth:sanctum']], function () {
    Route::get('logout', [AuthController::class, 'logout']);
    Route::post('edit/{id}', [UserManage\UserController::class, 'edit']);
    //个人中心查看服务/需求详情
    Route::get('/user-object-show/{id}', [UserManage\UserController::class, 'objectShow']);
    //个人中心服务/需求列表
    Route::get('/user-object-index', [UserManage\UserController::class, 'objectIndex']);

    //收藏相关
    Route::post('favorite', [UserManage\UserController::class, 'favorite']);
    Route::get('favorite-index', [UserManage\UserController::class, 'favoriteIndex']);
});


#######################################################################
#                   服务商相关接口
#######################################################################
Route::group(['prefix' => 'business', 'middleware' => ['auth:sanctum']], function () {
    Route::get('register', [UserManage\BusinessController::class, 'store']);
    Route::post('edit/{id}', [UserManage\BusinessController::class, 'edit']);
    Route::post('show/{id}', [UserManage\BusinessController::class, 'show']);
});


#######################################################################
#                   需求相关接口
#######################################################################
Route::group(['prefix' => 'demand'], function () {
    Route::get('search', [Demand\DemandController::class, 'search']);
    Route::get('/{id}', [Demand\DemandController::class, 'show']);
    Route::get('/add-views/{id}', [Demand\DemandController::class, 'addViews']);
});

Route::group(['prefix' => 'demand', 'middleware' => ['auth:sanctum']], function () {
    Route::post('store', [Demand\DemandController::class, 'store']);
    Route::post('delete/{id}', [Demand\DemandController::class, 'delete']);
    Route::post('edit/{id}', [Demand\DemandController::class, 'edit']);
});


#######################################################################
#                    服务相关接口
#######################################################################
Route::group(['prefix' => 'service'], function () {
    Route::get('search', [Service\ServiceController::class, 'search']);
    Route::get('/{id}', [Service\ServiceController::class, 'show']);
    Route::get('/add-views/{id}', [Service\ServiceController::class, 'addViews']);
});
Route::group(['prefix' => 'service', 'middleware' => ['auth:sanctum']], function () {
    Route::post('store', [Service\ServiceController::class, 'store']);
    Route::post('delete/{id}', [Service\ServiceController::class, 'delete']);
    Route::post('edit/{id}', [Service\ServiceController::class, 'edit']);
});


#######################################################################
#                   接单处理相关接口
#######################################################################
Route::group(['prefix' => 'apply', 'middleware' => ['auth:sanctum']], function () {
    Route::get('origin-search', [Apply\UserObjectController::class, 'originSearch']);
    Route::get('target-search', [Apply\UserObjectController::class, 'targetSearch']);
    Route::get('show/{id}', [Apply\UserObjectController::class, 'show']);
    Route::post('store', [Apply\UserObjectController::class, 'store']);
    Route::post('delete/{id}', [Apply\UserObjectController::class, 'delete']);
});


#######################################################################
#                   后台边缘管理模块
#######################################################################
// Route::group(['middleware' => ['auth:sanctum']], function () {
Route::group(['prefix' => ''], function () {

    // Banner管理
    Route::group(['prefix' => 'banner'], function () {
        Route::get('search', [EdgeManage\BannerController::class, 'search']);
    });

    //类型管理
    Route::group(['prefix' => 'type'], function () {
        Route::get('search', [EdgeManage\TypeController::class, 'search']);
    });

    //反馈问题管理
    Route::group(['prefix' => 'problem'], function () {
        Route::get('search', [EdgeManage\ProblemController::class, 'search']);
    });

    //地址管理
    Route::group(['prefix' => 'region'], function () {
        Route::get('search', [EdgeManage\RegionController::class, 'search']);
    });
});

Route::group(['middleware' => ['auth:sanctum']], function () {
    //反馈问题管理
    Route::group(['prefix' => 'problem'], function () {
        Route::post('store', [EdgeManage\ProblemController::class, 'store']);
    });
});
